package com.example.translateappjava.Service.FoodDetails;

import com.example.translateappjava.Service.FoodDetails.FoodDetailsInterface;

import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class FoodDetailsImplication implements FoodDetailsInterface.FoodDetailsGet {
    private static final String API_URL = "https://www.mxnzp.com/api/food_heat/food/details";
    private static final String AUTH_ID = "rgihdrm0kslojqvm";
    private static final String AUTH_SECRET = "WnhrK251TWlUUThqaVFWbG5OeGQwdz09";
//    https://www.mxnzp.com/api/food_heat/food/details?foodId=your&app_id=your&app_secret=your
    @Override
    public String getFoodDetailsResult(String id) throws IOException {
        String url = API_URL+"?foodId="+ id +"&app_id="+AUTH_ID+"&app_secret="+AUTH_SECRET;
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url(url)
                .build();
        try (Response response = okHttpClient.newCall(request).execute()){
            System.out.println("Response Code: "+ response.code());
            System.out.println(response.body().string());
            String res = response.toString();
            return res;
        }
        catch (IOException e){
            e.printStackTrace();
        }
        return "没有返回值";
    }
}
